<?php
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
$page = $_GET['page'];
if (is_numeric($page) == false) {
    $page = 1;
    $page_1 = 1;
    $min = 0;
    $page_2 = $page + 1;
} else {
    if ($page > 1) {
        $page_2 = $page + 1;
        $min = ($page - 1) * 35;
        $page_1 = $page - 1;
    } else {
        $page_1 = 1;
        $min = 0;
        $page_2 = 2;
    }
}

if($_GET['action'] == "del"){
	$id = $_GET['id'];
	$res = $mysql->execute("delete from `fre_questions` where `id`={$id}");
	if($res){
		echo "<script>alert('删除成功');location.href='common_question.php'</script>";
	}else{
		echo "<script>alert('删除失败');location.href='common_question.php'</script>";
	}
}
$i = 0;
$sql = "select * from fre_questions";
$results = $mysql->query($sql)
?>

<?php include('head.php') ?>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span10">
            <h1 class="page-title">常见问题列表</h1>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <div class="well">
                        	<a href="./add_comquestion.php" class="btn btn-primary">添加问题</a>
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <th>常见问题</th>
                                    <th>问提解析</th>
                                </tr>
                                </thead>
                                <tbody>
                              		<?php
                              		
                              			foreach($results as $result){
                              				$i++;
                              	print <<<table
        <tr>
          <td>$i</td>	
          <td>{$result['title']}</td>
     	  <td>{$result['content']}</td>
     	   <td>
     	   <a class="btn btn-primary" target="_blank" title="编辑" href="./edit_comquestion.php?id={$result['id']}">编辑</a>
			<a class="btn btn-danger" title="删除" href="javascript:if(confirm('确认删除？')){window.location.href = './common_question.php?id={$result['id']}&action=del';}">删除</a>
		  </td>
        </tr>
table;
                              			}
                              			
                              			?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="profile">
                    </div>
                </div>
				
            </div>

        </div>
    </div>


</div>

<footer>
    <hr>

    <p class="pull-right"><!--power by right--></p>


    <p><!--power by --></p>
</footer>



<script src="lib/bootstrap/js/bootstrap.js"></script>
<script language="JavaScript">
    function del_id(id) {
        if (confirm("确认封号？")) {
            location.href = "?del_id=" + id;
        } else {
            return false;
        }
    }
</script>


</body>
</html>